<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="spd" tagdir="/WEB-INF/tags/admin/"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<spd:resources />
<title>Spdzen</title>
</head>
<body class="spdui hold-transition skin-blue sidebar-mini fixed">
<div class="wrapper">
	<jsp:include page="nav.jsp"></jsp:include>	
	<div class="content-wrapper" id="mainWrapper">
		<div class="nav-tabs-custom" id="mainTabs">
            <ul class="nav nav-tabs" id="mainNavTabs">
                <li class="active" role="presentation">
					<a href="#mainTabHome" data-toggle="tab"><i class="fa fa-home"></i><span>首页</span></a>
				</li>
            </ul>
			<!-- /#mainNavTabs -->
            <div class="tab-content">
                <div class="tab-pane active" id="mainTabHome" role="tabpanel">
					<iframe src="http://www.baidu.com" style="width:100%;border:0;outline:0;"></iframe>
                </div>
            </div>
			<!-- /.tab-content -->
        </div>
		<!-- /#mainTabs -->
	</div>
	<!-- /.content-wrapper -->
</div>
<!-- /.wrapper -->

<form id="formChangeMyPwd" class="form-horizontal spd-form" method="post" style="display:none;">
	<table class="table table-bordered spd-table">
		<tbody>
			<tr>
				<td style="width:100px;"><label class="spd-label">当前密码</label></td>
				<td>
					<div class="spd-validate">
						<input class="form-control" type="password" name="oldPwd" placeholder="必填">
					</div>
				</td>
			</tr>
			<tr>
				<td><label class="spd-label">新密码</label></td>
				<td>
					<div class="spd-validate">
						<input class="form-control" type="password" name="newPwd" placeholder="必填">
					</div>
				</td>
			</tr>
			<tr>
				<td><label class="spd-label">确认新密码</label></td>
				<td>
					<div class="spd-validate">
						<input class="form-control" type="password" name="confirmPwd" placeholder="必填">
					</div>
				</td>
			</tr>
		</tbody>
	</table>
</form>
<!-- /#formChangeMyPwd -->

<spd:jslibs />

<script type="text/javascript">
$(function() {
	SpdUI.initFrame();
	
	SpdUI.getJSON({
		url: SpdUI.contextPath + '/admin/getCurrentUser.do',
		failure: false,
		success: function(data, json){
			$('#topmenuUser').find('[data-name="loginName"]').html(data.loginName);
		}
	});
	
	(function(){
		var showSidebar = function(show){
			var $mainSidebar = $('#mainSidebar'),
				$mainWrapper = $('#mainWrapper');
			
			if(show){
				$mainSidebar.show();
				$mainWrapper.css('margin-left', '170px');
			}else{
				$mainSidebar.hide();
				$mainWrapper.css('margin-left', '0');
			}
		};
		
		//showSidebar(false);
		
		$('#topmenus').on('click', 'a', function(){
			var $this = $(this);
			
			$('#topmenus').children('li').removeClass('active');
			$this.parent().addClass('active');
			
			var type = $this.data('type'),
				url = $this.data('url');
			if(type == 1 || type == 2) {
				showSidebar(false);
				
				url && SpdUI.addTab({
					id: $this.data('code'),
					title: $this.data('name'),
					url: url
				});
				
				return false;
			}
			
			$('#mainSidebarMenu').html('');
			SpdUI.getJSON({
				url: SpdUI.contextPath + '/admin/frame/getSubMenus.do?pid=' + $this.data('id'),
				success: function(data, json){
					var $mainSidebar = $('#mainSidebar');
					if(data == null || data.length == 0){
						showSidebar(false);
						return;
					}
					
					var bfn = function(nodes){
						var tmp = '';
						
						if(nodes == null || !$.isArray(nodes)){
							return tmp;
						}
						
						$.each(nodes, function(i, node){
							if(node.isParent){
								tmp += '<li class="treeview spd-menu-item">';
							}else{
								tmp += '<li class="spd-menu-item">';
							}
							
							tmp += '<a href="javascript:void(0);" data-url="' + SpdUI.contextPath + node.nodeData.url + '" data-id="' + node.nodeData.id + '" data-code="' + node.nodeData.code + '" data-type="' + node.nodeData.type + '" data-name="' + node.nodeData.name + '">';
							
							if(node.isParent){
								tmp += '<i class="fa fa-fw fa-caret-right"></i>';
							}
							
							var icon = $.trim(node.nodeData.icon);
							if(icon){
								tmp += '<i class="fa fa-fw ' + node.nodeData.icon + '"></i>';
							}
							
							tmp += '<span>' + node.nodeData.name + '</span>';
							
							tmp += '</a>';
							
							if(node.isParent){
								tmp += '<ul class="treeview-menu">';
								tmp += bfn(node.children);
								tmp += '</ul>';
							}
							
							tmp += '</li>';
						});
						
						return tmp;
					};
					
					var html = bfn(data);					
					if(html){
						showSidebar(true);
						$('#mainSidebarMenu').html(html);						
					}else{
						showSidebar(false);
					}					
				}
			});
			
			return false;
		});
		
		SpdUI.getJSON({
			url: SpdUI.contextPath + '/admin/frame/getTopMenus.do',
			success: function(data, json){
				if(data == null || data.length == 0){
					return;
				}
				
				var html = '';
				$.each(data, function(i, v){
					var tmp = '<li><a href="javascript:void(0);" ';
					tmp += 'data-type="' + v.type + '" ';
					tmp += 'data-id="' + v.id + '" ';
					tmp += 'data-name="' + v.name + '" ';
					tmp += 'data-url="' + SpdUI.contextPath + v.url + '" ';
					tmp += 'data-code="' + v.code + '" ';
					tmp += '>';
					
					var icon = $.trim(v.icon);
					if(icon){
						tmp += '<i class="fa fa-fw ' + icon + '"></i>';
					}
					
					tmp += '<span>' + v.name + '</span></a></li>';
					html += tmp;
				});
				
				$('#topmenus').html(html);
				$('#topmenus').find('a[data-code="sysManager"]').trigger('click');
			},
			failure: function(json, message){
				SpdUI.alert('菜单加载失败，请刷新页面重新加载！');
			}
		});
	})();
	
	(function(){
		SpdUI.addFnCode('changeMyPwd', function(data){
			SpdUI.openFormDialog('#formChangeMyPwd');
		});
		
		SpdUI.addFnCode('logout', function(data){
			SpdUI.confirm('确定退出系统？', function(){
				window.location.href = SpdUI.contextPath + '/admin/logout.do?rt=' + new Date().getTime();
			});
		});
		
		$('#topmenuUser').on('click', 'a[data-action]', function(){
			var $this = $(this), action = $(this).data('action');
			if(action){
				SpdUI.runFnCode(action);
			}
		});
	})();
	
	SpdUI.formDialog('#formChangeMyPwd', {
		title: '修改密码',
		validate: {
			oldPwd: {
				rule: 'required;length(6~20);',
				msg: '请输入6~20个字符的当前密码。'
			},
			newPwd: {
				rule: 'required;length(6~20);match(neq, oldPwd);',
				msg: {
					required: '请输入6~20个字符的新密码。',
					length: '请输入6~20个字符的新密码。',
					match: '新密码不能与当前密码一样。'
				}
			},
			confirmPwd: {
				rule: 'match(newPwd);',
				msg: '两次输入的密码不一致。'
			}
		},
		onsubmit: function($form, formData, dialog, dialogData){
			
		}
	});
});
</script>
</body>
</html>